home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 5
/
MacMania 5.toast
/
/
Internet software
/
NewsWatcher
/
NW Source
/
Source
/
child.c
< prev
next >
Wrap
Text File
|
1997-01-09
|
4KB
|
139 lines
/*----------------------------------------------------------------------------
child.c
This module manages the parent/child window relationship
Copyright © 1994-1997, Northwestern University.
----------------------------------------------------------------------------*/
#include "glob.h"
#include "child.h"
#include "memutil.h"
#include "group.h"
/*----------------------------------------------------------------------------
AddChild
Add a child window to the child window list of a parent window.
Entry: parent = pointer to parent window.
child = pointer to child window.
Exit: function result = error code.
----------------------------------------------------------------------------*/
OSErr AddChild (WindowPtr parent, WindowPtr child)
{
TWindow **parentInfo;
TChild **newChild;
OSErr err = noErr;
parentInfo = (TWindow**) GetWRefCon(parent);
err = MyNewHandle(sizeof(TChild), &newChild);
if (err != noErr) return err;
(**newChild).childWindow = child;
(**newChild).next = (**parentInfo).childList;
(**parentInfo).childList = newChild;
return noErr;
}
/*----------------------------------------------------------------------------
RemoveChild
Remove a child window from the child window list of a parent window.
Entry: parent = pointer to parent window.
child = pointer to child window.
----------------------------------------------------------------------------*/
void RemoveChild (WindowPtr parent, WindowPtr child)
{
TWindow **parentInfo;
TChild **current, **prev;
if (parent == nil) return;
parentInfo = (TWindow**) GetWRefCon(parent);
for (current = prev = (**parentInfo).childList;
current != nil && (**current).childWindow != child;
prev = current, current = (**current).next) /* do nothing */;
if (current != nil) {
if (prev == current) {
(**parentInfo).childList = (**current).next;
} else {
(**prev).next = (**current).next;
}
MyDisposeHandle(current);
}
}
/*----------------------------------------------------------------------------
FindChildByIndex
Locate a child window from an index in a group or subject array.
Entry: wind = pointer to group or subject window.
index = index in group or subject array.
Exit: function result = pointer to child window, or nil if none.
----------------------------------------------------------------------------*/
WindowPtr FindChildByIndex (WindowPtr wind, long index)
{
TWindow **info, **childInfo;
TChild **childListRec;
WindowPtr child;
TWindowKind kind;
info = (TWindow**)GetWRefCon(wind);
kind = (**info).kind;
for (childListRec = (**info).childList; childListRec != nil;
childListRec = (**childListRec).next)
{
child = (**childListRec).childWindow;
childInfo = (TWindow**)GetWRefCon(child);
if (kind == kSubject) {
if ((**childInfo).parentSubject == index) return child;
} else {
if ((**childInfo).parentGroup == index) return child;
}
}
return nil;
}
/*----------------------------------------------------------------------------
FindChild
Locate a child window corresponding to an item in a group or subject
window list.
Entry: wind = pointer to group or subject window.
item = item number in the window list.
Exit: function result = pointer to child window, or nil if none.
----------------------------------------------------------------------------*/
WindowPtr FindChild (WindowPtr wind, long item)
{
TWindow **info;
long index;
info = (TWindow**)GetWRefCon(wind);
if ((**info).kind == kGroup) {
index = BigLGetData((**info).groupList, item);
} else {
index = BigLGetData((**info).subjectList, item);
}
return FindChildByIndex(wind, index);
}